#include "{{className}}.h"


/**
  @brief The {{ className }} class implemtation
  
  @date Auto generated on {% now "yyyy/MM/dd hh:mm:ss" %}
*/
namespace cyclone::parser
{
  {{returnType}} {{className}}::visit(ParseTree *context)
  {
    IF_NULLPTR_RETURN_DEFAULT(context);

    return defaultResult();
  }
  {{returnType}}  {{className}}::visit(TerminalNode *context)
  {
    IF_NULLPTR_RETURN_DEFAULT(context);
    return context->getText();
  }
  {{returnType}}  {{className}}::visit(ErrorNode *context)
  {
    IF_NULLPTR_RETURN_DEFAULT(context);
    return defaultResult();
  }
    {{returnType}}  {{className}}::visit(Token *context)
  {
    IF_NULLPTR_RETURN_DEFAULT(context);
    return context->getText();
  }

  {{returnType}}  {{className}}::defaultResult()
  {
    return Json();
  }
  //isAnonymousNode
{% for ruleCollection in elementsCollection %}
{{ returnType }}  {{className}}::visit ( FormalParser::{{ ruleCollection.contextName }} * ctx ){
    IF_NULLPTR_RETURN_DEFAULT(ctx);
    {{% if ruleCollection.isAnonymousNode %}
        return visitAnonymousNode(ctx);
    {% else %}
        auto jsonifyNode = JsonVisitorHelper::jsonifyRuleNode(ctx);
        {% for local in ruleCollection.locals %}
        jsonifyNode["{{ local|cut:'_'  }}"] = ctx->{{local}};
        {% endfor %}
        {{% if not ruleCollection.hasElement %}
            jsonifyNode["{{ ruleCollection.ruleName }}"] = visitAnonymousNode(ctx);
        {% else %}
          {% for element in ruleCollection.elements %}
            jsonifyNode["{{ element|cut:'_' }}"] = dispatch(ctx->{{element}});
          {% endfor %}
        {% endif %}
        return jsonifyNode;
    {% endif %}
}
{% endfor %}


} // namespace cyclone::parser
